# -*- encoding:utf-8 -*-

import re

__author__ = 'Shudong Ma'


class FileHandler(object):
    str = r'<li><a href=".*" target="_blank" title=".*">(.*?) (.*?)</a></li>'
    pattern = re.compile(str)

    def __init__(self):
        pass

    # 获取所有股票名字
    def get_stock_info(self, file_path):
        flag = 'SH'
        stock_list = list()
        with open(file_path, 'r') as stock_file:
            for row in stock_file:
                if row.startswith('==='):
                    flag = 'SZ'
                    continue
                tmp = self.pattern.match(row).groups()
                tmp = list(tmp)
                tmp[1] = flag + tmp[1]
                stock_list.append(tuple(tmp))
        return stock_list
